<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>File Source for example.php</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
						<h1>Source for file example.php</h1>
<p>Documentation is available at <a href="../core/_contrib_example_php.html">example.php</a></p>
<div class="src-code">
<pre><a name="a1"></a><br />1     <span class="src-php">&lt;?php</span><a name="a2"></a><br />2     <a name="a3"></a><br />3     <span class="src-doc">/**</span><a name="a4"></a><br />4     <span class="src-doc"> * GeSHi example script</span><a name="a5"></a><br />5     <span class="src-doc"> * --------------------</span><a name="a6"></a><br />6     <span class="src-doc"> * Just point your browser at this script (with geshi.php in the parent directory,</span><a name="a7"></a><br />7     <span class="src-doc"> * and the language files in subdirectory &quot;../geshi/&quot;)</span><a name="a8"></a><br />8     <span class="src-doc"> */</span><a name="a9"></a><br />9     <a name="a10"></a><br />10    <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-sym">!</span><span class="src-sym">@</span><span class="src-inc">include</span> <span class="src-str">'../geshi.php'</span><span class="src-sym">)</span> <span class="src-sym">{</span><a name="a11"></a><br />11        <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-sym">!</span><span class="src-sym">@</span><span class="src-inc">include</span> <span class="src-str">'geshi.php'</span><span class="src-sym">)</span> <span class="src-sym">{</span><a name="a12"></a><br />12            <span class="src-key">die</span><span class="src-sym">(</span><span class="src-str">'Could not find geshi.php - make sure it is in your include path!'</span><span class="src-sym">)</span>;<a name="a13"></a><br />13        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span><a name="a14"></a><br />14            <span class="src-var">$path</span> = <span class="src-str">'./'</span>;<a name="a15"></a><br />15        <span class="src-sym">}</span><a name="a16"></a><br />16    <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span><a name="a17"></a><br />17        <span class="src-var">$path</span> = <span class="src-str">'../'</span>;<a name="a18"></a><br />18    <span class="src-sym">}</span><a name="a19"></a><br />19    <a name="a20"></a><br />20    <span class="src-key">if</span> <span class="src-sym">(</span> isset<span class="src-sym">(</span><span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'submit'</span><span class="src-sym">]</span><span class="src-sym">)</span> <span class="src-sym">)</span><a name="a21"></a><br />21    <span class="src-sym">{</span><a name="a22"></a><br />22        <span class="src-key">if</span> <span class="src-sym">(</span> <a href="http://www.php.net/get_magic_quotes_gpc">get_magic_quotes_gpc</a><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">)</span> <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'source'</span><span class="src-sym">]</span> = <a href="http://www.php.net/stripslashes">stripslashes</a><span class="src-sym">(</span><span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'source'</span><span class="src-sym">]</span><span class="src-sym">)</span>;<a name="a23"></a><br />23        <span class="src-key">if</span> <span class="src-sym">(</span> <span class="src-sym">!</span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'source'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">)</span> <span class="src-sym">)</span><a name="a24"></a><br />24        <span class="src-sym">{</span><a name="a25"></a><br />25            <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'language'</span><span class="src-sym">]</span> = <a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">'#[^a-zA-Z0-9\-_]#'</span><span class="src-sym">,</span> <span class="src-str">''</span><span class="src-sym">,</span> <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'language'</span><span class="src-sym">]</span><span class="src-sym">)</span>;<a name="a26"></a><br />26            <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'source'</span><span class="src-sym">]</span> = <a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">''</span><span class="src-sym">,</span> <span class="src-sym">@</span><a href="http://www.php.net/file">file</a><span class="src-sym">(</span><span class="src-var">$path</span> . <span class="src-str">'geshi/'</span> . <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'language'</span><span class="src-sym">]</span> . <span class="src-str">'.php'</span><span class="src-sym">)</span><span class="src-sym">)</span>;<a name="a27"></a><br />27            <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'language'</span><span class="src-sym">]</span> = <span class="src-str">'php'</span>;<a name="a28"></a><br />28        <span class="src-sym">}</span><a name="a29"></a><br />29        <span class="src-var">$geshi</span> = <span class="src-key">new</span> <span class="src-id"><a href="../core/GeSHi.html">GeSHi</a></span><span class="src-sym">(</span><span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'source'</span><span class="src-sym">]</span><span class="src-sym">,</span> <span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'language'</span><span class="src-sym">]</span><span class="src-sym">)</span>;<a name="a30"></a><br />30        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_header_type</span><span class="src-sym">(</span><span class="src-id"><a href="../core/_geshi_php.html#defineGESHI_HEADER_PRE">GESHI_HEADER_PRE</a></span><span class="src-sym">)</span>;<a name="a31"></a><br />31        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">enable_classes</span><span class="src-sym">(</span><span class="src-sym">)</span>;<a name="a32"></a><br />32        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">enable_line_numbers</span><span class="src-sym">(</span><span class="src-id"><a href="../core/_geshi_php.html#defineGESHI_FANCY_LINE_NUMBERS">GESHI_FANCY_LINE_NUMBERS</a></span><span class="src-sym">,</span> <span class="src-num">5</span><span class="src-sym">)</span>;<a name="a33"></a><br />33        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_overall_style</span><span class="src-sym">(</span><span class="src-str">'color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;'</span><span class="src-sym">,</span> <span class="src-id">true</span><span class="src-sym">)</span>;<a name="a34"></a><br />34        <span class="src-comm">// Note the use of set_code_style to revert colours...</span><a name="a35"></a><br />35        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_line_style</span><span class="src-sym">(</span><span class="src-str">'font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;'</span><span class="src-sym">,</span> <span class="src-str">'font-weight: bold; color: #006060;'</span><span class="src-sym">,</span> <span class="src-id">true</span><span class="src-sym">)</span>;<a name="a36"></a><br />36        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_code_style</span><span class="src-sym">(</span><span class="src-str">'color: #000020;'</span><span class="src-sym">,</span> <span class="src-str">'color: #000020;'</span><span class="src-sym">)</span>;<a name="a37"></a><br />37    <a name="a38"></a><br />38        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_link_styles</span><span class="src-sym">(</span><span class="src-id"><a href="../core/_geshi_php.html#defineGESHI_LINK">GESHI_LINK</a></span><span class="src-sym">,</span> <span class="src-str">'color: #000060;'</span><span class="src-sym">)</span>;<a name="a39"></a><br />39        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_link_styles</span><span class="src-sym">(</span><span class="src-id"><a href="../core/_geshi_php.html#defineGESHI_HOVER">GESHI_HOVER</a></span><span class="src-sym">,</span> <span class="src-str">'background-color: #f0f000;'</span><span class="src-sym">)</span>;<a name="a40"></a><br />40    <a name="a41"></a><br />41        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_header_content</span><span class="src-sym">(</span><span class="src-str">'GeSHi &amp;copy; 2004, Nigel McNie. View source of example.php for example of using GeSHi'</span><span class="src-sym">)</span>;<a name="a42"></a><br />42        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_header_content_style</span><span class="src-sym">(</span><span class="src-str">'font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;'</span><span class="src-sym">)</span>;<a name="a43"></a><br />43    <a name="a44"></a><br />44        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_footer_content</span><span class="src-sym">(</span><span class="src-str">'Parsed in &lt;TIME&gt; seconds,  using GeSHi &lt;VERSION&gt;'</span><span class="src-sym">)</span>;<a name="a45"></a><br />45        <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">set_footer_content_style</span><span class="src-sym">(</span><span class="src-str">'font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;'</span><span class="src-sym">)</span>;<a name="a46"></a><br />46    <span class="src-sym">}</span><a name="a47"></a><br />47    <span class="src-php">?&gt;</span><a name="a48"></a><br />48    &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;<a name="a49"></a><br />49         &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;<a name="a50"></a><br />50    &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;<a name="a51"></a><br />51    &lt;head&gt;<a name="a52"></a><br />52    	&lt;title&gt;GeSHi examples&lt;/title&gt;<a name="a53"></a><br />53    	&lt;style type=&quot;text/css&quot;&gt;<a name="a54"></a><br />54    	&lt;!--<a name="a55"></a><br />55    	<span class="src-php">&lt;?php</span><a name="a56"></a><br />56        <span class="src-key">if</span> <span class="src-sym">(</span> isset<span class="src-sym">(</span><span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'submit'</span><span class="src-sym">]</span><span class="src-sym">)</span> <span class="src-sym">)</span><a name="a57"></a><br />57        <span class="src-sym">{</span><a name="a58"></a><br />58            echo <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">get_stylesheet</span><span class="src-sym">(</span><span class="src-sym">)</span>;<a name="a59"></a><br />59        <span class="src-sym">}</span><a name="a60"></a><br />60        <span class="src-php">?&gt;</span><a name="a61"></a><br />61    	html {<a name="a62"></a><br />62    		background-color: #f0f0f0;<a name="a63"></a><br />63    	}<a name="a64"></a><br />64    	body {<a name="a65"></a><br />65    		font-family: Verdana, Arial, sans-serif;<a name="a66"></a><br />66    		margin: 10px;<a name="a67"></a><br />67    		border: 2px solid #e0e0e0;<a name="a68"></a><br />68    		background-color: #fcfcfc;<a name="a69"></a><br />69    		padding: 5px;<a name="a70"></a><br />70    	}<a name="a71"></a><br />71    	h2 {<a name="a72"></a><br />72    		margin: .1em 0 .2em .5em;<a name="a73"></a><br />73    		border-bottom: 1px solid #b0b0b0;<a name="a74"></a><br />74    		color: #b0b0b0;<a name="a75"></a><br />75    		font-weight: normal;<a name="a76"></a><br />76    		font-size: 150%;<a name="a77"></a><br />77    	}<a name="a78"></a><br />78    	h3 {<a name="a79"></a><br />79    		margin: .1em 0 .2em .5em;<a name="a80"></a><br />80    		color: #b0b0b0;<a name="a81"></a><br />81    		font-weight: normal;<a name="a82"></a><br />82    		font-size: 120%;<a name="a83"></a><br />83    	}<a name="a84"></a><br />84    	#footer {<a name="a85"></a><br />85    		text-align: center;<a name="a86"></a><br />86    		font-size: 80%;<a name="a87"></a><br />87    		color: #a9a9a9;<a name="a88"></a><br />88    	}<a name="a89"></a><br />89    	#footer a {<a name="a90"></a><br />90    		color: #9999ff;<a name="a91"></a><br />91    	}<a name="a92"></a><br />92    	textarea {<a name="a93"></a><br />93    		border: 1px solid #b0b0b0;<a name="a94"></a><br />94    		font-size: 90%;<a name="a95"></a><br />95    		color: #333;<a name="a96"></a><br />96    		margin-left: 20px;<a name="a97"></a><br />97    	}<a name="a98"></a><br />98    	select, input {<a name="a99"></a><br />99    		margin-left: 20px;<a name="a100"></a><br />100   	}<a name="a101"></a><br />101   	p {<a name="a102"></a><br />102   		font-size: 90%;<a name="a103"></a><br />103   		margin-left: .5em;<a name="a104"></a><br />104   	}<a name="a105"></a><br />105   	--&gt;<a name="a106"></a><br />106   	&lt;/style&gt;<a name="a107"></a><br />107   &lt;/head&gt;<a name="a108"></a><br />108   &lt;body&gt;<a name="a109"></a><br />109   &lt;h2&gt;GeSHi Example Script&lt;/h2&gt;<a name="a110"></a><br />110   &lt;p&gt;To use this script, make sure that &lt;strong&gt;geshi.php&lt;/strong&gt; is in the parent directory, and that<a name="a111"></a><br />111   the language files are in a subdirectory of the parent directory called &lt;strong&gt;geshi/&lt;/strong&gt;&lt;/p&gt;<a name="a112"></a><br />112   &lt;p&gt;Enter your source and a language to highlight the source in and submit, or just choose a language to<a name="a113"></a><br />113   have that language file highlighted in PHP.&lt;/p&gt;<a name="a114"></a><br />114   <span class="src-php">&lt;?php</span><a name="a115"></a><br />115   <span class="src-key">if</span> <span class="src-sym">(</span> isset<span class="src-sym">(</span><span class="src-var">$_POST</span><span class="src-sym">[</span><span class="src-str">'submit'</span><span class="src-sym">]</span><span class="src-sym">)</span> <span class="src-sym">)</span><a name="a116"></a><br />116   <span class="src-sym">{</span><a name="a117"></a><br />117       echo <span class="src-var">$geshi</span><span class="src-sym">-&gt;</span><span class="src-id">parse_code</span><span class="src-sym">(</span><span class="src-sym">)</span>;<a name="a118"></a><br />118       echo <span class="src-str">'&lt;hr /&gt;'</span>;<a name="a119"></a><br />119   <span class="src-sym">}</span><a name="a120"></a><br />120   <span class="src-php">?&gt;</span><a name="a121"></a><br />121   &lt;form action=&quot;example.php&quot; method=&quot;post&quot;&gt;<a name="a122"></a><br />122   &lt;h3&gt;Source to highlight&lt;/h3&gt;<a name="a123"></a><br />123   &lt;textarea rows=&quot;10&quot; cols=&quot;60&quot; name=&quot;source&quot;&gt;&lt;/textarea&gt;<a name="a124"></a><br />124   &lt;h3&gt;Choose a language&lt;/h3&gt;<a name="a125"></a><br />125   &lt;select name=&quot;language&quot;&gt;<a name="a126"></a><br />126   <span class="src-php">&lt;?php</span><a name="a127"></a><br />127   <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-sym">!</span><span class="src-sym">(</span><span class="src-var">$dir</span> = <span class="src-sym">@</span><a href="http://www.php.net/opendir">opendir</a><span class="src-sym">(</span><a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span>__FILE__<span class="src-sym">)</span> . <span class="src-str">'/geshi'</span><span class="src-sym">)</span><span class="src-sym">)</span><span class="src-sym">)</span> <span class="src-sym">{</span><a name="a128"></a><br />128       <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-sym">!</span><span class="src-sym">(</span><span class="src-var">$dir</span> = <span class="src-sym">@</span><a href="http://www.php.net/opendir">opendir</a><span class="src-sym">(</span><a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span>__FILE__<span class="src-sym">)</span> . <span class="src-str">'/../geshi'</span><span class="src-sym">)</span><span class="src-sym">)</span><span class="src-sym">)</span> <span class="src-sym">{</span><a name="a129"></a><br />129           echo <span class="src-str">'&lt;option&gt;No languages available!&lt;/option&gt;'</span>;<a name="a130"></a><br />130       <span class="src-sym">}</span><a name="a131"></a><br />131   <span class="src-sym">}</span><a name="a132"></a><br />132   <span class="src-var">$languages</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span>;<a name="a133"></a><br />133   <span class="src-key">while</span> <span class="src-sym">(</span> <span class="src-var">$file</span> = <a href="http://www.php.net/readdir">readdir</a><span class="src-sym">(</span><span class="src-var">$dir</span><span class="src-sym">)</span> <span class="src-sym">)</span><a name="a134"></a><br />134   <span class="src-sym">{</span><a name="a135"></a><br />135       <span class="src-key">if</span> <span class="src-sym">(</span> <span class="src-var">$file</span> == <span class="src-str">'..'</span> || <span class="src-var">$file</span> == <span class="src-str">'.'</span> || <span class="src-sym">!</span><a href="http://www.php.net/stristr">stristr</a><span class="src-sym">(</span><span class="src-var">$file</span><span class="src-sym">,</span> <span class="src-str">'.'</span><span class="src-sym">)</span> || <span class="src-var">$file</span> == <span class="src-str">'css-gen.cfg'</span> <span class="src-sym">)</span> <span class="src-key">continue</span>;<a name="a136"></a><br />136       <span class="src-var">$lang</span> = <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$file</span><span class="src-sym">,</span> <span class="src-num">0</span><span class="src-sym">,</span>  <a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$file</span><span class="src-sym">,</span> <span class="src-str">'.'</span><span class="src-sym">)</span><span class="src-sym">)</span>;<a name="a137"></a><br />137       <span class="src-var">$languages</span><span class="src-sym">[</span><span class="src-sym">]</span> = <span class="src-var">$lang</span>;<a name="a138"></a><br />138   <span class="src-sym">}</span><a name="a139"></a><br />139   <a href="http://www.php.net/closedir">closedir</a><span class="src-sym">(</span><span class="src-var">$dir</span><span class="src-sym">)</span>;<a name="a140"></a><br />140   <a href="http://www.php.net/sort">sort</a><span class="src-sym">(</span><span class="src-var">$languages</span><span class="src-sym">)</span>;<a name="a141"></a><br />141   <span class="src-key">foreach</span> <span class="src-sym">(</span><span class="src-var">$languages</span> <span class="src-key">as</span> <span class="src-var">$lang</span><span class="src-sym">)</span> <span class="src-sym">{</span><a name="a142"></a><br />142       echo <span class="src-str">'&lt;option value=&quot;'</span> . <span class="src-var">$lang</span> . <span class="src-str">'&quot;&gt;'</span> . <span class="src-var">$lang</span> . <span class="src-str">&quot;&lt;/option&gt;\n&quot;</span>;<a name="a143"></a><br />143   <span class="src-sym">}</span><a name="a144"></a><br />144   <a name="a145"></a><br />145   <span class="src-php">?&gt;</span><a name="a146"></a><br />146   &lt;/select&gt;&lt;br /&gt;<a name="a147"></a><br />147   &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Highlight Source&quot;&gt;<a name="a148"></a><br />148   &lt;/form&gt;<a name="a149"></a><br />149   &lt;div id=&quot;footer&quot;&gt;GeSHi &amp;copy; Nigel McNie, 2004, released under the GNU GPL&lt;br /&gt;<a name="a150"></a><br />150   For a better demonstration, check out the &lt;a href=&quot;http://qbnz.com/highlighter/demo.php&quot;&gt;online demo&lt;/a&gt;<a name="a151"></a><br />151   &lt;/body&gt;<a name="a152"></a><br />152   &lt;/html&gt;</pre>
</div>
	<p class="notes" id="credit">
		Documentation generated on Thu, 22 Sep 2005 13:47:53 +1200 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.2.3</a>
	</p>
	</body>
</html>